# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=esptool
pkgver=4.1
pkgrel=0
pkgdesc="ESP8266 and ESP32 serial bootloader utility"
url="https://docs.espressif.com/projects/esptool"
license="GPL-2.0-or-later"
arch="noarch"
depends="python3 py3-cryptography py3-ecdsa py3-pyserial py3-bitstring py3-reedsolo"
makedepends="py3-build py3-installer py3-setuptools py3-wheel"
checkdepends="py3-elftools"
source="https://github.com/espressif/esptool/archive/v$pkgver/esptool-$pkgver.tar.gz"

build() {
	python3 -m build --no-isolation --wheel
}

check() {
	python3 -m installer -d testenv \
		dist/esptool-$pkgver-py3-none-any.whl

	local sitedir="$(python3 -c 'import site;print(site.getsitepackages()[0])')"

	for test in imagegen espsecure merge_bin modules; do
		PYTHONPATH="$PWD/testenv/$sitedir" python3 test/test_$test.py
	done
}

package() {
	python3 -m installer -d "$pkgdir" \
		dist/esptool-$pkgver-py3-none-any.whl
}

sha512sums="
b9df8d361fe1a97f0649fed03abc919df1c2ff118dc4dd05abeec641ba2d16e6c308894bd91657768e03a6801ec9e5393e573b4c3016b624e842fef7c6354b41  esptool-4.1.tar.gz
"
